<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MVC.
 *
 * PHP-MVC is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MVC is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MVC; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-mvc
 * @subpackage  util
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */

/**
 * A simple JavaBean to encapsulate the request parameters sent for an HTML
 * input element of type image. Such an element causes two parameters to be
 * sent, one each for the X and Y coordinates of the button press. An instance
 * of this bean within an <code>ActionForm</code> can be used to capture these
 * and provide a simple means of detecting whether or not the corresponding
 * image was selected.
 */
class ImageButtonBean {

    /**
     * The X coordinate of the button press.
     */
    private $x;

    /**
     * The Y coordinate of the button press.
     */
    private $y;

    // ----------------------------------------------------------- Constructors

    /**
     * Construct an instance with the supplied property values.
     *
     * @param x The X coordinate of the button press.
     * @param y The Y coordinate of the button press.
     */
    public function __construct($x=null, $y=null) {
        $this->x = $x;
        $this->y = $y;
    }

    public function getX() {
        return ($this->x);
    }

    public function setX($x) {
        $this->x = $x;
    }

    public function getY() {
        return ($this->y);
    }

    public function setY($y) {
        $this->y = $y;
    }

    // --------------------------------------------------------- Public Methods

    /**
     * A convenience method to determine whether or not the corresponding
     * image element was selected.
     */
    public function isSelected() {
        return ((!is_null($this->x)) || (!is_null($this->y)));
    }

    /**
     * Return a string representation of this object.
     */
    public function __toString() {
        $sb = "ImageButtonBean[";

        $sb.=$this->x;
        $sb.=", ";
        $sb.=$this->y;
        $sb.="]";

        return $sb;
    }


}
?>